Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@babel/plugin-transform-new-target
Advanced tools
The @babel/plugin-transform-new-target npm package is designed to transform instances of the `new.target` meta-property within functions. This is particularly useful for compiling ES6 code to be compatible with environments that do not support the `new.target` syntax. The `new.target` property is used within constructors to determine if the constructor was called with the `new` operator, allowing constructors to identify how they were invoked and to behave differently if necessary.
Transforming new.target
This feature allows the transformation of `new.target` usage into a form that can be understood by environments that do not support this syntax. It checks if the constructor was called with `new` and throws an error if it wasn't, ensuring that the constructor behaves as intended even in older JavaScript environments.
function MyConstructor() {\n if (!new.target) {\n throw 'MyConstructor must be called with new';\n }\n console.log('MyConstructor was called with new');\n}\n// Transformed Code:\nfunction MyConstructor() {\n var _newtarget = this instanceof MyConstructor ? this.constructor : void 0;\n if (!_newtarget) {\n throw 'MyConstructor must be called with new';\n }\n console.log('MyConstructor was called with new');\n}
Similar to @babel/plugin-transform-new-target, this package transforms ES6 arrow functions into function expressions that older JavaScript environments can understand. While it focuses on arrow functions rather than the `new.target` property, both plugins serve the purpose of making modern JavaScript code compatible with older environments.
This package transforms ES6 class syntax into equivalent ES5 constructor functions. Like @babel/plugin-transform-new-target, it deals with issues related to constructor functions and their invocation, ensuring that class-based code can run in environments that do not support the ES6 class syntax.
Transforms new.target meta property
See our website @babel/plugin-transform-new-target for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-new-target
or using yarn:
yarn add @babel/plugin-transform-new-target --dev
v7.25.9 (2024-10-22)
babel-parser
, babel-template
, babel-types
syntacticPlaceholders
mode (@liuxingbaoyu)babel-helper-compilation-targets
, babel-preset-env
ClassAccessorProperty
to prevent the no-undef
rule (@victorenator)babel-parser
, babel-types
VISITOR_KEYS
etc. faster to access (@liuxingbaoyu)FAQs
Transforms new.target meta property
The npm package @babel/plugin-transform-new-target receives a total of 17,607,329 weekly downloads. As such, @babel/plugin-transform-new-target popularity was classified as popular.
We found that @babel/plugin-transform-new-target demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.